package com.yanqu.road.entity.activity.youxing.config;

import com.yanqu.road.entity.activity.ActivityConfig;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.config.goods.MallInfo;
import com.yanqu.road.entity.enums.eActivityConfigType;
import com.yanqu.road.utils.RandomHelper;
import com.yanqu.road.utils.string.StringUtils;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

public class XingYouConfig {

    private ActivityInfo activityInfo;

    private List<XingYouShanShuiEventInfo> eventInfoList;

    private List<XingYouShanShuiGridInfo> gridInfoList;

    private List<XingYouShanShuiRoleInfo> roleInfoList;

    /**
     * 初始个人默认银票，队伍总量=个人数量*队伍人数
     */
    private int SHANSHUI_START_SILVER_COIN;
    /**
     * 普通骰子id
     */
    private int SHANSHUI_NORMAL_COIN_ID;
    /**
     * 银票道具id
     */
    private int SHANSHUI_SILVER_COIN_ID;
    /**
     * 金页子道具id
     */
    private int SHANSHUI_GOLD_COIN_ID;
    /**
     * 专属骰子道具id
     */
    private int SHANSHUI_EXCLUSIVE_DICE_ID;
    /**
     * 漂泊骰子道具id
     */
    private int SHANSHUI_WANDER_DICE_ID;
    /**
     * 自选骰子道具id
     */
    private int SHANSHUI_MECHANICAL_DICE_ID;
    /**
     * 行囊道具id，用于补充专属骰子数量
     */
    private int SHANSHUI_TIPS_ID;
    /**
     * 通行证道具id
     */
    private int SHANSHUI_PASS_ID;
    /**
     * 开工利是道具id
     */
    private int SHANSHUI_RED_ENVELOPE_ID;
    /**
     * 扩建图道具id
     */
    private int SHANSHUI_EXPANSION_PLAN_ID;
    /**
     * 每个锦囊可补充的骰子数量
     */
    private int SHANSHUI_TIPS_NUM;
    /**
     * 玩家初始和上限骰子数
     */
    private int SHANSHUI_DICE_INITIAL_NUM;
    /**
     * 骰子回复时间，单位-秒
     */
    private int SHANSHUI_DICE_RECOVER_TIME;
    /**
     * 玩家地图
     */
    private List<Integer> SHANSHUI_MAP;
    /**
     * 漂泊地图
     */
    private List<Integer> SHANSHUI_OTHER_MAP;
    /**
     * 占据妈祖庙后，替换玩家地图
     */
    private List<Integer> SHANSHUI_TOWER_MAP;
    /**
     * 初始协助次数
     */
    private int SHANSHUI_HELP_TIME;
    /**
     * 累计消耗N1点体力可以增加N2次协助次数
     */
    private List<Integer> SHANSHUI_HELP_RECOVER_TIME;
    /**
     * 宝华御街商品配置，道具id=数量|银票价格;道具id=数量|银票价格
     */
    private String SHANSHUI_SHOP_CONFIG;
    /**
     * 漂泊地图最多同时存在n个其他玩家
     */
    private int SHANSHUI_MAP_NUM_LIMIT;
    /**
     * 妈祖庙默认怪物配置，格式：怪物id|等级
     */
    private List<String> SHANSHUI_DEFAULT_MONSTER;
    /**
     * 前往漂泊地图获得基础银票
     */
    private int SHANSHUI_OTHER_MAP_BASE_REWARD;
    /**
     * 自动功能解锁需要消耗常规骰子数
     */
    private int SHANSHUI_AUTO_CONFIG;
    /**
     * 扩建图满级回收成金页子配置
     */
    private String SHANSHUI_EXPANSION_PLAN_RECYCLE;
    /**
     * 开战期时间配置(开启时间；结束时间）单位：分钟
     */
    private List<Integer> SHANSHUI_FIGHT_TIME;

    /**
     * 战斗事件美女数量
     */
    private int BATTLE_BEAUTY_NUM;
    /**
     * 每个美女最多攻击次数
     */
    private int BEAUTY_ATTACK_NUM;
    /**
     * 队伍日志最大上限
     */
    private int SHANSHUI_LOG_LIMIT;
    /**
     * 协战日志最大上限
     */
    private int SHANSHUI_BATTLE_LOG_LIMIT;

    /**
     * 宣言长度
     */
    private int SHANSHUI_DECLARATION_NUM;

    /**
     * 同步战力cd
     */
    private int SHANSHUI_POWER_COOL_TIME;

    /**
     * 重新发宣言内置cd（单位：s）
     */
    private int SHANSHUI_ANNOUNCE_RESET_TIME;

    /**
     * 妈祖庙战斗保护时间（单位：s）
     */
    private int SHUISHUI_MAZU_PROTECT_TIME;

    /**
     * 配置现金礼包有效时长（单位 s）
     */
    //private int SHANSHUI_CASH_GIFT_KEEP_TIME;

    /**
     * 现金礼包
     */
    //public Map<Integer, Map<Integer, MallInfo>> rmbMallInfoTypeMap = new ConcurrentHashMap<>(); //rmb礼包 k:type k:vip,v:MallInfo

    private List<Long> POWER_PARAM = StringUtils.stringToLongList("10|4|2","\\|");

    private String SHANSHUI_BAG_RECLAIM;
    /**
     * 初始化相关配置
     * @param activityConfigMap 活动配置map
     */
    public void initConfig(Map<String, ActivityConfig> activityConfigMap) {


        SHANSHUI_START_SILVER_COIN = activityConfigMap.get(eActivityConfigType.SHANSHUI_START_SILVER_COIN.getName()).getIntValue();
        SHANSHUI_NORMAL_COIN_ID = activityConfigMap.get(eActivityConfigType.SHANSHUI_NORMAL_COIN_ID.getName()).getIntValue();
        SHANSHUI_SILVER_COIN_ID = activityConfigMap.get(eActivityConfigType.SHANSHUI_SILVER_COIN_ID.getName()).getIntValue();
        SHANSHUI_GOLD_COIN_ID = activityConfigMap.get(eActivityConfigType.SHANSHUI_GOLD_COIN_ID.getName()).getIntValue();
        SHANSHUI_EXCLUSIVE_DICE_ID = activityConfigMap.get(eActivityConfigType.SHANSHUI_EXCLUSIVE_DICE_ID.getName()).getIntValue();
        SHANSHUI_WANDER_DICE_ID = activityConfigMap.get(eActivityConfigType.SHANSHUI_WANDER_DICE_ID.getName()).getIntValue();
        SHANSHUI_MECHANICAL_DICE_ID = activityConfigMap.get(eActivityConfigType.SHANSHUI_MECHANICAL_DICE_ID.getName()).getIntValue();
        SHANSHUI_TIPS_ID = activityConfigMap.get(eActivityConfigType.SHANSHUI_TIPS_ID.getName()).getIntValue();
        SHANSHUI_PASS_ID = activityConfigMap.get(eActivityConfigType.SHANSHUI_PASS_ID.getName()).getIntValue();
        SHANSHUI_RED_ENVELOPE_ID = activityConfigMap.get(eActivityConfigType.SHANSHUI_RED_ENVELOPE_ID.getName()).getIntValue();
        SHANSHUI_EXPANSION_PLAN_ID = activityConfigMap.get(eActivityConfigType.SHANSHUI_EXPANSION_PLAN_ID.getName()).getIntValue();
        SHANSHUI_TIPS_NUM = activityConfigMap.get(eActivityConfigType.SHANSHUI_TIPS_NUM.getName()).getIntValue();
        SHANSHUI_DICE_INITIAL_NUM = activityConfigMap.get(eActivityConfigType.SHANSHUI_DICE_INITIAL_NUM.getName()).getIntValue();
        SHANSHUI_DICE_RECOVER_TIME = activityConfigMap.get(eActivityConfigType.SHANSHUI_DICE_RECOVER_TIME.getName()).getIntValue();

        SHANSHUI_MAP = Collections.unmodifiableList(StringUtils.stringToIntegerList(activityConfigMap.get(eActivityConfigType.SHANSHUI_MAP.getName()).getValue(), "\\|"));
        SHANSHUI_OTHER_MAP = Collections.unmodifiableList(StringUtils.stringToIntegerList(activityConfigMap.get(eActivityConfigType.SHANSHUI_OTHER_MAP.getName()).getValue(), "\\|"));
        SHANSHUI_TOWER_MAP = Collections.unmodifiableList(StringUtils.stringToIntegerList(activityConfigMap.get(eActivityConfigType.SHANSHUI_TOWER_MAP.getName()).getValue(), "\\|"));

        SHANSHUI_HELP_TIME = activityConfigMap.get(eActivityConfigType.SHANSHUI_HELP_TIME.getName()).getIntValue();

        SHANSHUI_HELP_RECOVER_TIME = Collections.unmodifiableList(StringUtils.stringToIntegerList(activityConfigMap.get(eActivityConfigType.SHANSHUI_HELP_RECOVER_TIME.getName()).getValue(), "\\|"));

        SHANSHUI_SHOP_CONFIG = activityConfigMap.get(eActivityConfigType.SHANSHUI_SHOP_CONFIG.getName()).getValue();
        SHANSHUI_MAP_NUM_LIMIT = activityConfigMap.get(eActivityConfigType.SHANSHUI_MAP_NUM_LIMIT.getName()).getIntValue();
        SHANSHUI_DEFAULT_MONSTER = Collections.unmodifiableList(StringUtils.stringToStringList(activityConfigMap.get(eActivityConfigType.SHANSHUI_DEFAULT_MONSTER.getName()).getValue(), ";"));
        SHANSHUI_OTHER_MAP_BASE_REWARD = activityConfigMap.get(eActivityConfigType.SHANSHUI_OTHER_MAP_BASE_REWARD.getName()).getIntValue();
        SHANSHUI_AUTO_CONFIG = activityConfigMap.get(eActivityConfigType.SHANSHUI_AUTO_CONFIG.getName()).getIntValue();
        SHANSHUI_EXPANSION_PLAN_RECYCLE = activityConfigMap.get(eActivityConfigType.SHANSHUI_EXPANSION_PLAN_RECYCLE.getName()).getValue();

        SHANSHUI_FIGHT_TIME = Collections.unmodifiableList(StringUtils.stringToIntegerList(activityConfigMap.get(eActivityConfigType.SHANSHUI_FIGHT_TIME.getName()).getValue(), ";"));

        BATTLE_BEAUTY_NUM = activityConfigMap.get(eActivityConfigType.BATTLE_BEAUTY_NUM.getName()).getIntValue();
        BEAUTY_ATTACK_NUM = activityConfigMap.get(eActivityConfigType.BEAUTY_ATTACK_NUM.getName()).getIntValue();
        SHANSHUI_LOG_LIMIT = activityConfigMap.get(eActivityConfigType.SHANSHUI_LOG_LIMIT.getName()).getIntValue();
        SHANSHUI_BATTLE_LOG_LIMIT = activityConfigMap.get(eActivityConfigType.SHANSHUI_BATTLE_LOG_LIMIT.getName()).getIntValue();

        SHANSHUI_DECLARATION_NUM = activityConfigMap.get(eActivityConfigType.SHANSHUI_DECLARATION_NUM.getName()).getIntValue();
        SHANSHUI_POWER_COOL_TIME = activityConfigMap.get(eActivityConfigType.SHANSHUI_POWER_COOL_TIME.getName()).getIntValue();
        SHANSHUI_ANNOUNCE_RESET_TIME = activityConfigMap.get(eActivityConfigType.SHANSHUI_ANNOUNCE_RESET_TIME.getName()).getIntValue();
        SHUISHUI_MAZU_PROTECT_TIME = activityConfigMap.get(eActivityConfigType.SHUISHUI_MAZU_PROTECT_TIME.getName()).getIntValue();
//        SHANSHUI_CASH_GIFT_KEEP_TIME = activityConfigMap.get(eActivityConfigType.SHANSHUI_CASH_GIFT_KEEP_TIME.getName()).getIntValue();

        SHANSHUI_BAG_RECLAIM = activityConfigMap.get(eActivityConfigType.SHANSHUI_BAG_RECLAIM.getName()).getValue();

    }

    /**
     * 转换战力
     * @param ability
     * @return
     */
    public long transformPatronsPower(long ability) {
//        long param1 = this.getPowerParam().get(0);
//        long param2 = this.getPowerParam().get(1);
//        long param3 = this.getPowerParam().get(2);
//        //计算
//        double logValue1 = (double) ability / param1;
//        double logValue2 = Math.log(logValue1);//底数为e的log计算
//        long power = (long) (logValue2 * param2);
//        return Math.max(power, param3);
        return ability;
    }

    /**
     * 是否经营建筑
     */
    public boolean isBuildGrid(int gridId) {
        for (XingYouShanShuiGridInfo gridInfo : gridInfoList) {
            if(gridInfo.getId() == gridId && gridInfo.getType() == 2){
                return true;
            }
        }
        return false;
    }

    public XingYouShanShuiEventInfo randomXingYouShanShuiEventInfo() {
        List<Integer> weightList = new ArrayList<>();
        for (XingYouShanShuiEventInfo eventInfo : eventInfoList) {
            weightList.add(eventInfo.getWeight());
        }
        int index = RandomHelper.getRandomIndexByWeight(weightList, new Random());
        return eventInfoList.get(index);
    }

    public XingYouShanShuiRoleInfo getRoleInfo(int roleId){
        for (XingYouShanShuiRoleInfo roleInfo : roleInfoList) {
            if(roleInfo.getId() == roleId){
                return roleInfo;
            }
        }
        return null;
    }

    public XingYouShanShuiGridInfo getGridInfo(int gridId){
        for (XingYouShanShuiGridInfo gridInfo : gridInfoList) {
            if(gridInfo.getId() == gridId){
                return gridInfo;
            }
        }
        return null;
    }

    public XingYouShanShuiEventInfo getEventInfo(int eventId){
        for (XingYouShanShuiEventInfo eventInfo : eventInfoList) {
            if(eventInfo.getId() == eventId){
                return eventInfo;
            }
        }
        return null;
    }

    public ActivityInfo getActivityInfo() {
        return activityInfo;
    }

    public void setActivityInfo(ActivityInfo activityInfo) {
        this.activityInfo = activityInfo;
    }

    public void setEventInfoList(List<XingYouShanShuiEventInfo> eventInfoList) {
        this.eventInfoList = eventInfoList;
    }

    public void setGridInfoList(List<XingYouShanShuiGridInfo> gridInfoList) {
        this.gridInfoList = gridInfoList;
    }

    public void setRoleInfoList(List<XingYouShanShuiRoleInfo> roleInfoList) {
        this.roleInfoList = roleInfoList;
    }

    public List<XingYouShanShuiEventInfo> getEventInfoList() {
        return eventInfoList;
    }

    public List<XingYouShanShuiGridInfo> getGridInfoList() {
        return gridInfoList;
    }

    public List<XingYouShanShuiRoleInfo> getRoleInfoList() {
        return roleInfoList;
    }

    public int getSHANSHUI_START_SILVER_COIN() {
        return SHANSHUI_START_SILVER_COIN;
    }

    public int getSHANSHUI_NORMAL_COIN_ID() {
        return SHANSHUI_NORMAL_COIN_ID;
    }

    public int getSHANSHUI_SILVER_COIN_ID() {
        return SHANSHUI_SILVER_COIN_ID;
    }

    public int getSHANSHUI_GOLD_COIN_ID() {
        return SHANSHUI_GOLD_COIN_ID;
    }

    public int getSHANSHUI_EXCLUSIVE_DICE_ID() {
        return SHANSHUI_EXCLUSIVE_DICE_ID;
    }

    public int getSHANSHUI_WANDER_DICE_ID() {
        return SHANSHUI_WANDER_DICE_ID;
    }

    public int getSHANSHUI_MECHANICAL_DICE_ID() {
        return SHANSHUI_MECHANICAL_DICE_ID;
    }

    public int getSHANSHUI_TIPS_ID() {
        return SHANSHUI_TIPS_ID;
    }

    public int getSHANSHUI_PASS_ID() {
        return SHANSHUI_PASS_ID;
    }

    public int getSHANSHUI_RED_ENVELOPE_ID() {
        return SHANSHUI_RED_ENVELOPE_ID;
    }

    public int getSHANSHUI_EXPANSION_PLAN_ID() {
        return SHANSHUI_EXPANSION_PLAN_ID;
    }

    public int getSHANSHUI_TIPS_NUM() {
        return SHANSHUI_TIPS_NUM;
    }

    public int getSHANSHUI_DICE_INITIAL_NUM() {
        return SHANSHUI_DICE_INITIAL_NUM;
    }

    public int getSHANSHUI_DICE_RECOVER_TIME() {
        return SHANSHUI_DICE_RECOVER_TIME;
    }

    public List<Integer> getSHANSHUI_MAP() {
        return SHANSHUI_MAP;
    }

    public List<Integer> getSHANSHUI_OTHER_MAP() {
        return SHANSHUI_OTHER_MAP;
    }

    public List<Integer> getSHANSHUI_TOWER_MAP() {
        return SHANSHUI_TOWER_MAP;
    }

    public int getSHANSHUI_HELP_TIME() {
        return SHANSHUI_HELP_TIME;
    }

    public List<Integer> getSHANSHUI_HELP_RECOVER_TIME() {
        return SHANSHUI_HELP_RECOVER_TIME;
    }

    public String getSHANSHUI_SHOP_CONFIG() {
        return SHANSHUI_SHOP_CONFIG;
    }

    public int getSHANSHUI_MAP_NUM_LIMIT() {
        return SHANSHUI_MAP_NUM_LIMIT;
    }

    public List<String> getSHANSHUI_DEFAULT_MONSTER() {
        return SHANSHUI_DEFAULT_MONSTER;
    }

    public int getSHANSHUI_OTHER_MAP_BASE_REWARD() {
        return SHANSHUI_OTHER_MAP_BASE_REWARD;
    }

    public int getSHANSHUI_AUTO_CONFIG() {
        return SHANSHUI_AUTO_CONFIG;
    }

    public String getSHANSHUI_EXPANSION_PLAN_RECYCLE() {
        return SHANSHUI_EXPANSION_PLAN_RECYCLE;
    }

    public List<Integer> getSHANSHUI_FIGHT_TIME() {
        return SHANSHUI_FIGHT_TIME;
    }

    public int getBATTLE_BEAUTY_NUM() {
        return BATTLE_BEAUTY_NUM;
    }

    public int getBEAUTY_ATTACK_NUM() {
        return BEAUTY_ATTACK_NUM;
    }

    public int getSHANSHUI_LOG_LIMIT() {
        return SHANSHUI_LOG_LIMIT;
    }

    public int getSHANSHUI_BATTLE_LOG_LIMIT() {
        return SHANSHUI_BATTLE_LOG_LIMIT;
    }

    public List<Long> getPowerParam(){
        return POWER_PARAM;
    }

    public int getSHANSHUI_DECLARATION_NUM() {
        return SHANSHUI_DECLARATION_NUM;
    }

    public int getSHANSHUI_POWER_COOL_TIME() {
        return SHANSHUI_POWER_COOL_TIME;
    }

    public int getSHANSHUI_ANNOUNCE_RESET_TIME() {
        return SHANSHUI_ANNOUNCE_RESET_TIME;
    }

    public int getSHUISHUI_MAZU_PROTECT_TIME() {
        return SHUISHUI_MAZU_PROTECT_TIME;
    }

    public String getSHANSHUI_BAG_RECLAIM() {
        return SHANSHUI_BAG_RECLAIM;
    }

    public void setSHANSHUI_BAG_RECLAIM(String SHANSHUI_BAG_RECLAIM) {
        this.SHANSHUI_BAG_RECLAIM = SHANSHUI_BAG_RECLAIM;
    }
}
